import { PageVo, post } from '../../common/http/http.service'

export interface StoryRecord {
  book: boolean;
  id: string;
  storyId: number | null;
  cover: string;
  userId: number;
  nickName: string;
  avatar: string;
  title: string;        // 故事标题
  content: string;      // 故事内容
  user: boolean;        // 我创建的
  collect: boolean;     // 我收藏的
  browse: boolean;      // 我浏览过的
}

interface pageType {
  storyId?: string //故事Id
  type: string //数据类型 1:浏览 2：收藏 3：转发 4:点赞 5:制作 
  pageNo: string //页码
  pageSize: string //每页显示数量
}

export interface StoryDetail {
  collectNum: number;
  praiseNum: number;
  forwardNum: number;
  makeNum: number
};
export interface UserDetail {
  isCollect: boolean;
  isPraise: boolean;
  isShare: boolean;
  isMake: boolean;
};
export interface CreateDetail {
  createId: string;
  createName: string;
  createAvatar: string;
};

export interface StoryInfo {
  detail: StoryDetail;
  user: UserDetail;
  creater: CreateDetail;
}

export type RecordType = 'browse' | 'collect' | 'forward' | 'praise' | 'make'

/*
 * @Description: 登陆模块请求
 * @Author: liuzhen
 */
export class RecordService {

  // 历史列表
  page(params: any): Promise<PageVo<StoryRecord>> {
    return post('/story/api/record/page', params)
  }

  // 查询操作记录
  collectRecordPage(params: pageType): Promise<any> {
    return post('/story/api/collectRecord/page', params)
  }

  // 查询故事信息
  getStoryInfo(rcdId: string): Promise<StoryInfo> {
    return post('/story/api/record/storyInfo', { rcdId });
  }

  // 添加点赞，收藏等
  onAdd(rcdId: string, type: RecordType): Promise<any> {
    return post('/story/api/record/add', { rcdId, type });
  }

  // 删除点赞，收藏等
  onRemove(rcdId: string, type: RecordType): Promise<any> {
    return post('/story/api/record/remove', { rcdId, type });
  }
}

